import ListNode

class Solution:
    def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
        #! to add 
        carry = 0
        tail = None
        header = l1
        while (not l1 is None) and (not l2 is None):
            tmp = int ((l1.val + l2.val + carry ) / 10)
            l1.val = (l1.val + l2.val + carry ) % 10
            carry = tmp; tail = l1
            l1 = l1.next; l2 = l2.next

        if l1 is None:
            l1 = l2
            tail.next = l2

        while not l1 is None:
            tmp  =  int((l1.val + carry ) / 10)
            l1.val = (l1.val + carry) % 10
            carry = tmp
            tail = l1; l1 = l1.next

        if carry > 0:
            tail.next = ListNode(carry)

        return header    